'use strict';
module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/video/pub/getPayTv 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid,
			type,
			tv_id,
			drama_id,
			user_id
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		//tv_id要么为空，要么为未定义。
		if (!tv_id || tv_id === "") {
			let info = await vk.baseDao.findByWhereJson({
				dbName: "a_tv",
				whereJson: {
					drama_id: Number(drama_id),
				}
			});
			tv_id = info._id;
		}


		tv_id = "64dc6cf9fe975fba5af66f7b"
		if (type === "payData") {
			res.payData = await vk.baseDao.select({
				dbName: "a_had_pay", // 表名
				getCount: false, // 是否需要同时查询满足条件的记录总数量，默认false
				getMain: false, // 是否只返回rows数据，默认false
				pageIndex: 1, // 当前第几页
				pageSize: 1, // 每页条数
				whereJson: { // 条件
					tv_id: tv_id,
					user_id: user_id,
				},
				// 代表只显示_id和money字段
				fieldJson: {
					_id: true,
					series: true,
				},
				// 按_id降序 asc 升序 desc 降序 
				sortArr: [
					{ name: "series", type: "desc" }
				],
			});
		}


		if (type === "aTv") {
			let info = await vk.baseDao.findById({
				dbName: "a_tv",
				id: tv_id,
				fieldJson: {
					_id: true,
					start_needpay: true,
				},
			});
			res.series = info.start_needpay - 1;
		}




		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}